package com.aabte.auth.tracker.model;

import com.aabte.auth.shared.model.BaseModelUseLongPK;
import com.aabte.commons.ddd.shared.DomainEntity;
import lombok.Getter;
import lombok.ToString;

import javax.persistence.*;
import java.time.Instant;

@SuppressWarnings("all")
@Entity
@Table(name = "tb_tracker")
@Getter
@ToString
public class Tracker extends BaseModelUseLongPK implements DomainEntity<Tracker, TrackerId> {

    @Embedded
    private TrackerId trackerId;

    @Column(unique = true, nullable = false, length = 32)
    private String eventId;

    private Instant startTime;

    private Instant completedTime;

    private Integer retryCounter;

    @Enumerated(value = EnumType.ORDINAL)
    private Status status;

    private Tracker() {
    }

    public Tracker(TrackerId trackerId, String eventId, Instant startTime, Instant completedTime, Integer retryCounter, Status status) {
        this.trackerId = trackerId;
        this.eventId = eventId;
        this.startTime = startTime;
        this.completedTime = completedTime;
        this.retryCounter = retryCounter;
        this.status = status;
    }

    @Override
    public boolean sameIdentityAs(Tracker tracker) {
        return this.trackerId.equals(tracker.trackerId);
    }

    @Override
    public TrackerId identity() {
        return this.trackerId;
    }
}
